var prefix = jsctx + "/pileOffline";

var pileOfflineDetail = (function () {
    function init() {
        setTimeout(function () {//防止先于-读取缓存执行
            load();
        }, 10)
    };

    $('#exampleTable').on('load-success.bs.table', function (e, data) {
        if (data.total && !data.rows.length) {
            $('#exampleTable').bootstrapTable('selectPage').bootstrapTable('refresh');
        }
    });
    var h = $(window).height() - 180;

    function load() {
        $('#exampleTable')
            .bootstrapTable(
                {
                    method: 'get',
                    url: prefix + "/listPagePileOfflineDetail",
                    iconSize: 'outline',
                    toolbar: '#exampleToolbar',
                    striped: false,
                    dataType: "json",
                    pagination: true,
                    singleSelect: false,
                    pageSize: 10,
                    pageList: [10, 20, 30],
                    pageNumber: 1,
                    sidePagination: "server",
                    paginationShowPageGo: true,
                    height: h,
                    // showColumns: true,
                    // rightFixedColumns: true,
                    cache: false,
                    queryParams: function (params) {
                        return {
                            limit: params.limit,
                            offset: (params.offset / params.limit) + 1,
                            elecPileId: $("#elecPileId").val().trim(),
                            beginTime: $("#beginTime").val().trim(),
                            endTime: $("#endTime").val().trim(),
                        };
                    },
                    columns: [
                        {
                            title: '#', field: '', width: '50', align: 'left',
                            formatter: function (value, row, index) {
                                return index + 1;
                            }
                        },
                        {field: 'stationName', title: '桩群', align: 'left', width: '100'},
                        {field: 'pileNo', title: '桩编号', width: '100', align: 'left'},
                        {field: 'pileElecType', title: '电桩类型', width: '100', align: 'left'},
                        {field: 'brandName', title: '桩品牌', width: '100', class: 'operateBefore-td',  align: 'left'},
                        {field: 'beginTime', title: '离线时间', width: '100',  align: 'left'},
                        {field: 'endTime', title: '恢复时间', width: '100',  align: 'left'},
                        {field: 'offlineTime', title: '离线时长', width: '100', align: 'left'},
                    ]
                });
    }

    function reLoad() {
        $('#exampleTable').bootstrapTable('refresh');
        selectPileOfflineInfo()
    }


    function goBack() {
        location.href = prefix + "/index";
    }


    function exportPileOfflineDetail() {
        $.fileDownload(prefix + "/exportPileOfflineDetail", { // 后台请求链接
            httpMethod: "get",　　　　　　　　// 请求方式
            contentType: 'application/json',　 // 请求头
            data: {　　　　　　　　　　　　　　　// 参数，左边为后台接收的参数名，右边为前端获取的值，
                elecPileId: $("#elecPileId").val().trim(),
                beginTime: $("#beginTime").val().trim(),
                endTime: $("#endTime").val().trim()
            },
            prepareCallback: function (url) {
                layer.msg("文件下载中...", {time: -1})
            },
            abortCallback: function (url) {
                // 异常终止
                layer.msg("文件下载异常！！");
            },
            successCallback: function (url) {
                layer.msg("文件下载成功！！", {time: 1500});
            },
            failCallback: function (data) {
                var str = "{" + data.substring(data.indexOf("{") + 1, data.indexOf("}")) + "}";
                layer.msg(JSON.parse(str).message);
            }
        })
    }


    return {
        init: init,
        goBack: goBack,
        reLoad: reLoad,
        exportPileOfflineDetail: exportPileOfflineDetail,
    };
})();


